    //
//  TextLiveController.m
//  NBANews
//
//  Created by Liccon Chang on 11-1-14.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "TextLiveController.h"
#import "ColumnView.h"

@implementation TextLiveController

//@synthesize mainTable;
//@synthesize liveData;

@synthesize LiveWeb;
@synthesize WebStatus;

// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
	[super loadView];
	self.title = @"文字直播";
	CGRect rect = self.view.frame;
	int infoHeight = 0;
	if (self.topGameInfo != nil) {
		UIView* infoView = [self CreateGameInfoView:self.topGameInfo];
		infoHeight = infoView.frame.size.height;
		[self.view addSubview:infoView];
		[infoView release];
	}
	rect.size.width = self.view.frame.size.height;
	rect.origin.x = 0;
	rect.origin.y = infoHeight;
	rect.size.height = self.view.frame.size.width - TabBarHeight - NarBarHeight - StateBarHeight - infoHeight;
	
	//
//	mainTable = [[UITableView alloc] initWithFrame:rect style:UITableViewStyleGrouped];
//	mainTable.dataSource = self;
//	mainTable.delegate = self;
//	[self.view addSubview:mainTable];
	
	//
	LiveWeb = [[UIWebView alloc] initWithFrame:rect];
	LiveWeb.delegate = self;
	LiveWeb.autoresizesSubviews = YES;
	[self.view addSubview:LiveWeb];
	WebStatus = 0;
	
	[self InsertAdvertisementsView];
}

- (void)viewDidAppear:(BOOL)animated{
	[self LoadWebView:WebStatus];
}

- (void) LoadWebView:(int) aStatus{
	switch (WebStatus) {
		case 0:
			WebStatus = 2;
			//request from url 
			//NSString* url = [NSString stringWithFormat:[Constant getAddress:ETextLiveTelecast],topGameInfo.sid];
			NSString* url = @"http://bf.bet007.com/text/77553.htm";
			NSURLRequest* request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
			[LiveWeb loadRequest:request];
			[request release];
			break;
		case 1:
			WebStatus = 2;
			[LiveWeb reload];
			break;
		default:
			break;
	}
}

- (void)webViewDidStartLoad:(UIWebView *)webView{
	[self ShowWaiteLabel];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView{
	[self HideWaiteLabel];
	[self.LiveWeb stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '90%'"];
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
	[self HideWaiteLabel];
}
/////////////////////////////////////////////////////////////////
/*
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
	return 40.0;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tView {
	return 1;
}

- (NSInteger)tableView:(UITableView *)tView numberOfRowsInSection:(NSInteger)section {
	if (liveData) {
		return [liveData.RowDatas count];
	}
	return 0;
}


- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
	if (liveData) {
		return [liveData Title];
	}
	return @"";
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
	if (indexPath.row %2 !=0) {
		cell.backgroundColor = [UIColor colorWithRed:234.0f/255.0f green:219.0f/255.0f blue:222.0f/255.0f alpha:1.0f];
	}
}

-(UITableViewCell*)tableView:(UITableView *)tableView   cellForRowAtIndexPath:(NSIndexPath*)indexPath {
	
	static NSString *cellIndentifier = @"Cell";
	int row = [indexPath row];
	
	UITableViewCell*cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];
	if(cell ==  nil) {
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentifier] autorelease];
	}
	if (liveData) {
		RowData* rowData = [liveData.RowDatas objectAtIndex:row];
		UIView* cellView = [self CreateColumnView:rowData ColWidth:mainTable.frame.size.height];
		[cell.contentView addSubview:cellView];
		[cellView release];
	}
	return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)dealloc {
//	[mainTable release];
//	[liveData release];
	[LiveWeb release];
    [super dealloc];
}


@end
